package com.letv.whatslive.model.convert;

import com.letv.whatslive.model.AppAllows;
import com.letv.whatslive.model.Device;
import com.letv.whatslive.model.MapDeviceAndApp;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import org.apache.commons.lang3.StringUtils;

//2015.11.4

/**
 * Created by shenyue on 2015/11/4.
 */
public class MapDeviceAndAppConvert {
    public static DBObject castMapDeviceAndAppToDBObject(MapDeviceAndApp mapDeviceAndApp){
        DBObject dbo = new BasicDBObject();
        if(mapDeviceAndApp.getId() != null){
            dbo.put("_id",mapDeviceAndApp.getId());
        }
        if(mapDeviceAndApp.getDeviceId() != null)
            dbo.put("deviceId",mapDeviceAndApp.getDeviceId());

        if(mapDeviceAndApp.getAppId() != null)
            dbo.put("appId",mapDeviceAndApp.getAppId());

        return dbo;


//        DBObject dbo = new BasicDBObject();
//        if (device.getId() != null) {
//            dbo.put("_id", device.getId());
//        }
//        dbo.put("platformId",device.getPlatformId());
//        dbo.put("sysVer", device.getSysVer());
//        dbo.put("model", device.getModel());
//        dbo.put("appVer", device.getAppVer());
//        dbo.put("corporationId", device.getCorporationId());
//        dbo.put("channelId", device.getChannelId());
//        return dbo;
    }

    public static MapDeviceAndApp castDBObjectToMapDeviceAndApp(DBObject dbObject){
        MapDeviceAndApp mapDeviceAndApp = new MapDeviceAndApp();
        if(dbObject != null) {
            mapDeviceAndApp.setId(ObjUtils.toLong(dbObject.get("_id")));
            mapDeviceAndApp.setDeviceId(ObjUtils.toLong(dbObject.get("deviceId")));
            mapDeviceAndApp.setAppId(ObjUtils.toLong(dbObject.get("appId")));
        }

        return mapDeviceAndApp;
    }
}
